package com.heima.controller;


import com.heima.pojo.dto.LoginDto;
import com.heima.pojo.vo.LoginUserVo;
import com.heima.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/api/user-service/user")
@Slf4j
@Api("用户登录")
public class LoginController {

    @Autowired

    private UserService userService;

    /**
     * 登录
     * @param dto
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("登录")
    public LoginUserVo login(@RequestBody LoginDto dto){
       return userService.login(dto);
    }

    /**
     * 图片验证码
     * @return clientToken
     */

    @GetMapping("/imageCode/{clientToken}")
    @ApiOperation("图片验证码")
    public void getImageCode(@PathVariable String clientToken, HttpServletResponse response) throws IOException {
        userService.imgToken(clientToken, response);
    }

}
